import ElementUI from "element-ui";

const dialog=new class{

  constructor(){
    this.ElementUI=ElementUI;
  }

  /**
   *  加载提示
   */
  loadding(selector,background) {
    this.ElementUI.Loading.service({
      target:selector,
      background:background,
    })

    // var dom=document.querySelector(".login-form")
    // Dialog.loadding(dom,"rgba(255,255,255,0.5)")
  }

  /**
   * 提示登录
   */
  hintLogin() {
    this.customConfirm({
      title: '提示',
      message:"您的登陆已过期，请重新登陆",
      confirmButtonText: '去登陆',
      closeOnPressEscape: false,
      showCancelButton: true,
      callback(action,instance) {
        //console.log(action)
        if(action=="confirm"){
          location.href="https://anantaxi.com/ctrl/index.html"
        }
      }
    })
  }



  /**
   * 消息提示
   * @param title
   * @param msg
   * @param successCallback
   * @param cancelCallback
   */
  hint(title,msg,successCallback,cancelCallback) {
    this.ElementUI.MessageBox(msg,title, {
      distinguishCancelAndClose: true,
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      showCancelButton:true,
      callback(action,instance) {
        if(action=="confirm"&&successCallback){
          successCallback()
        }else if(action=="cancel"&&cancelCallback){
          cancelCallback();
        }
      }
    })
  }


  /**
   * 确定/取消对话框
   * @param title
   * @param msg
   * @param successCallback
   * @param cancelCallback
   */
  confirm(title,msg,successCallback,cancelCallback){
    this.ElementUI.MessageBox({
      title:title,
      message:msg,
      confirmButtonText: '确定',
      closeOnPressEscape: false,
      showCancelButton: true,
      callback(action,instance) {
        //console.log(action)
        if(action=="confirm"&&successCallback){
          successCallback()
        }else if(action=="cancel"&&cancelCallback){
          cancelCallback();
        }
      }
    })
  }

  // 自定义提示框
  customConfirm(options){
    this.ElementUI.MessageBox(options);
  }
}

export {dialog}
